package com.hshh.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hshh.util.CommonCommand;

public class SessionCheckInterceptor extends BaseInterceptor{
	private String[] nonSessionPage = {"/", "/index.do","/error.do","/auth.json"};
	@Override
	public boolean preHandle(HttpServletRequest request, 
			HttpServletResponse response, Object handler) throws Exception {
		//개발을 위한 테스트코드
		if(true){
			return true;
		}

		CommonCommand cc = new CommonCommand();
		if(cc.getSessionAuth(request)){
			return true;
		}
		else{
			String uri = ((HttpServletRequest)request).getRequestURI();
			for(int i = 0 ; i < nonSessionPage.length ; i++){
				if(uri.equals(nonSessionPage[i])){
					return true;
				}
			}
			response.sendRedirect("/error.do");
			return false;
		}
	}
}